<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表页</title>
    <link rel="stylesheet" href="./static/css/index.css">
</head>

<body>

    <div>
        <div>
            <h1>新增用户</h1>
        </div>
        <div>
            <table>
                <tr>
                    <td>
                        姓名: <input type="text" id="uname" placeholder="请输入姓名">
                    </td>
                    <td>
                        年龄: <input type="text" id="uage" placeholder="请输入年龄">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="button" value="保存" onclick="saveU()">
                        <input type="button" value="返回" onclick="cancelU()">
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <script src="./static/js/axios.min.js"></script>
    <script src="./static/js/jquery-3.7.1.min.js"></script>
    <script>
        //请求端口
        const api = "http://localhost:3000"

        function saveU() {
            let name = $('#uname').val()
            let age = $('#uage').val()

            axios.post(`${api}/user`, { name, age }).then(
                location.href = './index.html'
            )
        }

        function cancelU() {
            if (confirm("确认返回主页吗?")) {
                location.href = './index.html'
            }
        }
    </script>
</body>

</html>